package edu.ccut.saturn.studio.core.util.eclipse;

import java.io.File;

import edu.ccut.saturn.studio.core.saturnproperty.StringUtils;
import edu.ccut.saturn.studio.core.util.file.SaturnFileUtils;

/**
 * Eclipse路径工具类
 * 
 * @author 郭英杰
 * @version 1.0 2008.9.4
 */
public final class SaturnEclipsePathUtil {

	public static final String ECLIPSE_PLUG = "plugins";
	
	public static final String SATURN_ECLIPSE_PLUG = "saturn\\eclipse\\plugins";
	
	public static final String ECLIPSE_CONFIGURATION = "configuration";
	
	public static final String SATURN_DATABASE_FILE_PATH = ECLIPSE_CONFIGURATION
			+ StringUtils.DIRECOTRY_SEPARATOR  + "saturn_database_config"
			+ StringUtils.DIRECOTRY_SEPARATOR + "saturn_database_config.xml";

	/**
	 * 获取eclipse绝对路径
	 * 
	 * @return
	 */
	@SuppressWarnings("restriction")
	public static final String getEclipsePath() {
		return org.eclipse.core.internal.runtime.InternalPlatform.getDefault()
				.getInstallURL().getPath();
	}

	/**
	 * 获得SaturnDataBase 配置文件路径
	 * @return
	 */
	public static final File getDataBaseFile() {
		return SaturnFileUtils.getFile(getEclipsePath() + SATURN_DATABASE_FILE_PATH);
	}

	/**
	 * 获取eclipse plugins路径
	 * @return
	 */
	public static File getEclipsePluginDirectory() {
		return SaturnFileUtils.getFile(getEclipsePath() + ECLIPSE_PLUG);
	}
	
	/**
	 * 获取saturn/eclipse/plugins路径
	 * @return
	 */
	public static File getSaturnEclipsePluginDirectory() {
		String s = getEclipsePath();
		String[] paths = s.split("/");
		paths[paths.length - 1] = "";
		String temppath = "";
		for (String path : paths) {
			if(!"".equals(path)) {
				temppath = temppath + "/" + path ;
			}
		}
		return SaturnFileUtils.getFile(temppath + File.separator + SATURN_ECLIPSE_PLUG);
	}
	
	/**
	 * 获取eclipse configuration路径
	 * @return
	 */
	public static File getEclipseConfigurationDirectory() {
		return SaturnFileUtils.getFile(getEclipsePath() + ECLIPSE_CONFIGURATION);
	}
	
}
